<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>好货专场</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css"/>
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/zepto.min.js"></script>
    <script type="text/javascript" src="../script/aui-slide.js"></script>
    <script type="text/javascript" src="../script/common.js"></script>
    <script type="text/javascript" src="../script/doT.min.js"></script>
    <style>
        #header{
            background: #fff;
        }
        #header .aui-bar{
            background:transparent;
            color:#000;
            border-bottom:1px solid #ccc;
        }
        #header .aui-bar .aui-btn .aui-icon-left{
            color:#000;
        }
        .title{border-bottom: 1px solid #eee;margin-bottom: .5rem;}
        .title img{width: 2rem !important;height: 2rem;display: inline-block;}
        .aui-list .aui-list-item-title{font-size: .6rem;}
        .share_btn{font-size: .5rem;border-radius: 10rem;color: #fff;padding: .1rem .5rem;}
        .comment{height: 4rem;}
        .comment .c1{height: 3rem;padding-right: .5rem;}
        .comment .c1 span{border:1px dashed #f0392b;border-radius: .2rem;overflow-y: auto;height: 100%;display: block;padding: .3rem;}
        .comment .c2{background: #eee;text-align: center;border-radius: .2rem;padding: .2rem;height: 3rem;display: block;padding-top: .6rem;}
        .aui-list .aui-list-item:active{background: #fff;}
    </style>
</head>
<body>
  <section class="aui-content">
    <img src='../image/nine_nine_tj.png'>
          <ul class="aui-list aui-media-list" id="list">
          </ul>
      </section>
</body>
<script type="text/javascript">
    var renderLi,
        min_idVal = '1';
        String.prototype.replaceAll = function (FindText, RepText) {
            regExp = new RegExp(FindText, "g");
            return this.replace(regExp, RepText);
        }
    apiready = function () {
        renderLi = doT.template($api.html($api.byId('templateLimit')));
        getDataFrm()
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                threshold: 100 //设置距离底部多少距离时触发，默认值为0，数字类型
            }
        }, function (ret, err) {
            getDataFrm()
        });
    };
    function getDataFrm(){
      var urlTransform = window.urlTransformZGD(window.APIServerZGD.GoodGoods, {
          min_idVal: min_idVal
      })
      _Ajax(urlTransform, 'get', {}, 'json', function (ret) {
          if (ret.code === 1) {
              for (var i = 0; i < ret.data.length; i++) {
                var element = ret.data[i].item_data
                for (var j = 0; j < element.length; j++) {
                  element[j].item_id = element[j].itemid?element[j].itemid:''
                }
                ret.data[i].item_id = element[0].itemid
                ret.data[i].copy_text = ret.data[i].copy_text.replaceAll("&lt;br&gt;","<br/>")
              }

              $api.append($api.byId('list'), renderLi(ret));
              min_idVal = ret.min_id
          } else {
              // if ( ret.total=='0' && bool ) {
              //     //改变搜索条件后无条目返回置空
              //     $api.html($api.byId('ulList'), '');
              // }
              console.log(JSON.stringify(ret))
          }
      });
    }
    //复制
    function copyd(obj){
        var item_id = $(obj).parents('li').data('itemid');
        _loading('加载中...','',true);
        _Ajax(window.APIServer.Share,'post',{values:{item_id:item_id}},'json',function(ret){
            _loading_close();
            if (ret.code==1) {
                var text = $('#tkl_text').html();
                text = text.replace('$淘口令$',ret.data.tkl);
                $('#tkl_text').html(text);
                copy(text);
            }else{
                _toast(ret.msg)
            }
        });
    }
    //一键分享
    function share(obj){
        var item_id = $(obj).parents('li').data('itemid');
        _loading('加载中...','',true);
        _Ajax(window.APIServer.Share,'post',{values:{item_id:item_id}},'json',function(ret){
            _loading_close();
            if (ret.code==1) {
                //修改内容
                // var text = $('#tkl_text').html();
                // text = text.replace('$淘口令$',ret.data.tkl);
                // $('#tkl_text').html(text);
                // copy(text);
                //生成海报
                var types = ['淘宝','天猫','京东','拼多多'];
                var makeSharePic = api.require('makeSharePic');
                makeSharePic.makePicture({
                    imgUrl:ret.data.pic,
                    qrCode:ret.data.share_url,
                    expressType:types[ret.data.is_tmall],
                    goodTitle:'           '+ret.data.title,
                    nowPriceStatus:'现价 ：￥'+ret.data.price,
                    discountType:'券',
                    discountPrice:ret.data.quan_price+'元',
                    finalPriceType:'券后价 ',
                    finalPrice:ret.data.price_after_quan,
                    //    savePath:'cache://image',
                    //    fileName:'share.png',
                    insertImage:true,
                    //    isHtmlText:true,
                },function(ret,err){
                    _loading_close();
                    if(ret.status){
                        var sharedModule = api.require('shareAction');
                        sharedModule.share({
                          type: 'image',
                          path: ret.filePath
                        });
                      //$('#pics').prepend('<div class="aui-col-xs-3 dui"><label><img src="'+ret.filePath+'" /><input class="aui-radio" type="checkbox" name="demo" checked></label></div>');
                      //alert(JSON.stringify(ret));
                    }else{
                      _toast('分享海报生成失败');
                    }
                });
            }else{
                _toast(ret.msg)
            }
        });
    }
    // <img src="{{= value.itempic }}" onclick='photo_browser({{= JSON.stringify(it['data'][key]['item_data']['itempic']) }},{{=index}})' tapmoode />
</script>
<script id="templateLimit" type="text/x-dot-template">
{{ for (key in it.data){ }}
    <li class="aui-list-item" data-itemid="{{= it['data'][key]['item_id'] }}">
        <div class="aui-media-list-item-inner">
            <div class="aui-list-item-inner">

                <div class="aui-media-list-item-inner title">
                    <div class="aui-list-item-media" style="width: 3rem;">
                        <img src="../image/girl.jpg" class="aui-img-round aui-list-img-sm">
                    </div>
                    <div class="aui-list-item-inner ">
                        <div class="aui-list-item-text">
                            <div class="aui-list-item-title aui-font-size-14">小编推荐</div>
                            <div class="aui-list-item-right">
                                <div class="jb share_btn" onclick="share(this)"><span class="aui-iconfont aui-icon-share"></span>一键分享</div>
                            </div>
                        </div>
                        <div class="aui-list-item-text">
                            {{= formatDateTime(it['data'][key]['addtime']* 1000) }}
                        </div>
                    </div>
                </div>

                <div class="aui-list-item-text" style="color:#333;">
                    {{= it['data'][key]['copy_text'] }}
                </div>
                <div class="aui-list-item-text">
                    <div class="aui-row-padded" style="max-width:90%;">
                        {{~it['data'][key]['item_data']:value:index}}
                        <div class="aui-col-xs-4" >
                            <img src="{{= value.itempic }}" onclick='open_goods({{= JSON.stringify( it['data'][key]['item_data'][index] ) }})' tapmoode />
                        </div>
                        {{~}}
                    </div>
                </div>
            </div>
        </div>
    </li>
{{ } }}
</script>
</html>
